package com.qingshu.controller.custom;

import com.qingshu.common.annotation.Log;
import com.qingshu.common.entity.custom.Lyric;
import com.qingshu.common.entity.custom.model.LyricAddModel;
import com.qingshu.common.entity.custom.model.LyricUpdateModel;
import com.qingshu.common.enums.BusinessType;
import com.qingshu.common.util.body.JsonResult;
import com.qingshu.common.util.body.ResultTool;
import com.qingshu.common.util.model.ModelUtil;
import com.qingshu.service.ILyricService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Huzz
 * @since 2021-12-09
 */
@Api(tags = "歌词管理")
@RestController
@RequestMapping("/custom/lyric")
public class LyricController {

    @Autowired
    private ILyricService lyricService;

    @Log(title = "操作日志", businessType = BusinessType.INSERT, isSaveResponseParam = true)
    @ApiOperation(value = "添加歌词")
    @PostMapping("/addLyric")
    public JsonResult addLyric(@RequestBody LyricAddModel model){
        return lyricService.addLyric((Lyric) ModelUtil.toEntityStatic(model, Lyric.class)) ? ResultTool.success() : ResultTool.fail();
    }

    @Log(title = "操作日志", businessType = BusinessType.UPDATE, isSaveResponseParam = true)
    @ApiOperation(value = "根据id修改")
    @PutMapping("/updateLyricById")
    public JsonResult updateLyricById(LyricUpdateModel model){
        return lyricService.updateLyricById((Lyric) ModelUtil.toEntityStatic(model, Lyric.class)) ? ResultTool.success() : ResultTool.fail();
    }

    @Log(title = "操作日志", businessType = BusinessType.DELETE, isSaveResponseParam = true)
    @ApiOperation(value = "根据id删除")
    @DeleteMapping("/delLyricById")
    public JsonResult delLyricById(@ApiParam(required = true) Integer LyricId){
        return lyricService.delLyricById(LyricId) ? ResultTool.success() : ResultTool.fail("删除失败, 请检查是否存在数据关联");
    }

    @Log(title = "操作日志", businessType = BusinessType.SELECT)
    @ApiOperation(value = "查询分页列表")
    @GetMapping("/finRoleLyricPage")
    public JsonResult finUserLyricPage(@RequestParam(defaultValue = "1", required = false) Integer pageNum,
                                       @RequestParam(defaultValue = "10", required = false) Integer pageSize,
                                       Lyric model){
        return ResultTool.success(lyricService.findLyricPage(pageNum, pageSize, model));
    }

    @Log(title = "操作日志", businessType = BusinessType.SELECT)
    @ApiOperation(value = "根据id进行查询")
    @GetMapping("/finLyricById")
    public JsonResult finLyricById(Integer LyricId){
        return ResultTool.success(lyricService.finLyricById(LyricId));
    }

    @Log(title = "操作日志", businessType = BusinessType.SELECT)
    @ApiOperation(value = "根据音乐名称进行查询")
    @GetMapping("/finUserByLyricName")
    public JsonResult finUserByRoleName(String LyricName){
        return ResultTool.success(lyricService.finUserByRoleName(LyricName));
    }

}
